package HTMLParser.HTMLTag;

import Parser.Token;

/*******************************************************************************
 * This class deals with Font tags. Its main function is to extract and store
 * the different variables from a <font> tag. It stores the font face, the size
 * and the colour.
 * @author James Johnstone
 * @version FINAL
 *******************************************************************************/
public class Font extends Tag {

    private String font;
    private int size;
    private String colour;

    /*******************************************************************************
     * Constructor for the Font class. Takes one variable which is a Token
     * representing the HTML Tag (example: <FONT SIZE="10">). It then extracts the
     * colour, size, and face tags and stores them appropriately.
     * @param t A Token representing a HTML FONT tag.
     *******************************************************************************/
    public Font(Token t) {
        super(t, "Font");
        String tokenString = t.getToken().toLowerCase();
        if (tokenString.contains("size=" + '"')) {
            int first = tokenString.indexOf("size=" + '"') + 6;
            int last = tokenString.indexOf("" + '"', first);
            size = Integer.parseInt(tokenString.substring(first, last));
        } else {
            size = -1;
        }
        if (tokenString.contains("color=" + '"')) {
            int first = tokenString.indexOf("color=" + '"') + 7;
            int last = tokenString.indexOf("" + '"', first);
            colour = tokenString.substring(first, last);
        } else {
            colour = "";
        }
        if (tokenString.contains("face=" + '"')) {
            int first = tokenString.indexOf("face=" + '"') + 6;
            int last = tokenString.indexOf("" + '"', first);
            font = tokenString.substring(first, last);
        } else {
            font = "";
        }
    }

    /***************************************************************************
     * Gets the font face.
     * @return  A String containing the name of the font specified within
     * the Token.
     ***************************************************************************/
    public String getFont() {
        return font;
    }

    /***************************************************************************
     * Gets the font size.
     * @return  An int representing the size of the font specified within the
     * Token.
     ***************************************************************************/
    public int getFontSize() {
        return size;
    }

    /***************************************************************************
     * Gets the font colour.
     * @return  A String representing the colour of the font specified within
     * the Token.
     ***************************************************************************/
    public String getFontColour() {
        return colour;
    }
}
